package com.yidu.ladder.base.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yidu.ladder.base.domain.ArchiveVo;
import com.yidu.ladder.base.domain.Archives;
import com.yidu.ladder.base.service.ArchivesService;

/**
 * 基础档案控制器
 * @author bamboo
 *
 */
@Controller
@RequestMapping("/base/archives")
public class ArchivesController {
	@Autowired
	private ArchivesService archivesService;
	
	/**
	 * 得到基础档案service
	 * @return 基础档案service
	 */
	public ArchivesService getArchivesService() {
		return archivesService;
	}
	/**
	 * 修改基础档案service
	 * @param archivesService 基础档案service
	 */
	public void setArchivesService(ArchivesService archivesService) {
		this.archivesService = archivesService;
	}

	/**
	 * 分页查询基础档案
	 * @param archiveVo 基础档案包装类
	 * @return 键值对的数据
	 */
	@ResponseBody
	@RequestMapping(value="archives",method=RequestMethod.GET)
	public Map<String,Object> queryArchiveWithPage(ArchiveVo archiveVo){
		//分页查询基础档案并返回
		return archivesService.queryArchiveWithPage(archiveVo);
	}
	/**
	 * 根据基础档案是否分级查询相对应的基础档案
	 * @param classification 是否分级
	 * @return 基础档案集合
	 */
	@ResponseBody
	@RequestMapping(value="archive/{classification}",method=RequestMethod.GET)
	public List<Archives> findArchives(@PathVariable("classification") String classification){
		//调用service层根据是否分级查询基础档案的方法
		return archivesService.findByclassification(classification);
	}
	
	/**
	 * 添加基础档案
	 * @param archives 基础档案
	 * @return 添加成功返回true ，否则返回false
	 */
	@ResponseBody
	@RequestMapping(value="archive",method=RequestMethod.POST)
	public boolean addArchives(Archives archives) {
		//调用service层添加基础档案并返回
		return archivesService.saveArchives(archives);
	}
	/**
	 * 修改基础档案
	 * @param archives 基础档案
	 * @return 修改成功返回true，否则返回false
	 */
	@ResponseBody
	@RequestMapping(value="archive",method=RequestMethod.PUT)
	public boolean updateArchives(Archives archives) {
		//调用service层修改基础档案并返回
		return archivesService.updateArchives(archives);
		
	}
	/**
	 * 冻结或还原基础档案
	 * @param archivesIds 基础档案Id
	 * @param useable 是否可用
	 * @return 结果字符串
	 */
	@ResponseBody
	@RequestMapping(value="archive/{archivesId}/{useable}",method=RequestMethod.DELETE)
	public String frozenORrecoverArchives(@PathVariable("archivesId") String archivesIds, @PathVariable("useable") String useable) {
		//调用service冻结或还原方法
		boolean result = archivesService.frozenOrRecoveArchives(archivesIds, useable);
		//如果结果为false，就返回fail字符串
		if(result==false) {
			return "fail";
		}
		//否则返回success
		return "success";
		
	}
	
	
}
